package learning.objectStream;

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ObjectStream4 {
	public static void main(String[] args) {
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		try {
			// oos=new ObjectOutputStream(new
			// FileOutputStream("myfile/me.txt",true));
			// oos.writeObject(new Creature("Cat","black"));
			// oos.writeObject(new Creature("Dog","black"));
			// oos.writeObject(new Creature("Ant","black"));
			ois = new ObjectInputStream(new FileInputStream("myfile/me.txt"));
			Object o = null;
			while ((o = ois.readObject()) != null) {
				System.out.println((Creature) o);
			}

		} catch (EOFException e) {
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (oos != null)
				try {
					oos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}

}

class Creature implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String name;
	String cilor;

	public Creature(String name, String cilor) {
		super();
		this.name = name;
		this.cilor = cilor;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.name + "  " + this.cilor;
	}
}